import axios from "axios";
import CryptoJS from "crypto-js";

export async function downloadImg(url){
    let ret = new ArrayBuffer()
    await axios({
        url: url,
        responseType: 'arraybuffer'
    }).then(res=>{
        ret = res.data
    })
    return ret
}
export function getMemberIDByName(name, employeeList){
    let result = "";
    employeeList.forEach((item,index)=>{
        if(item["name"]==name){
            result = item["id"];
        }
    })
    return result;
}

export function CNMEn(word, keyStr=""){
    keyStr = keyStr ? keyStr : "absoietlj32fai88";
    let key = CryptoJS.enc.Utf8.parse(keyStr);
    let srcs = CryptoJS.enc.Utf8.parse(word);
    let encrypted = CryptoJS.AES.encrypt(srcs, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString();
}
export function CNMDe(word, keyStr=""){
    keyStr = keyStr ? keyStr : "absoietlj32fai88";
    var key = CryptoJS.enc.Utf8.parse(keyStr);
    var decrypt = CryptoJS.AES.decrypt(word, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}
export async function sendLog(sendData){
    let url = "https://dc-api.tju.ink/api/index/log";
    // let url = "http://localhost:8888/api/index/log";
    let ret = 0;
    await axios({
        method: "post",
        data: sendData,
        url: url
    }).then((res) => {
        console.log("sendLog-->",  res);
        ret = res["data"]["data"]["countTimes"];
    })
    return ret;
}
